/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[IteratorTag.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package jsp.tag;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * 将一个标签体内容转输出指定次数到浏览器
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class IteratorTag extends SimpleTagSupport {

	private String iteratorCount;

	public void setIteratorCount(String iteratorCount) {
		this.iteratorCount = iteratorCount;
	}

	@Override
	public void doTag() throws JspException, IOException {
		JspFragment fragment = this.getJspBody();
		StringWriter out = new StringWriter();
		fragment.invoke(out);
		// 获得标签体内容
		String content = out.toString();

		JspWriter writer = this.getJspContext().getOut();
		for (int i = 0; i < Integer.parseInt(iteratorCount); i++) {
			writer.print(content + "<br />");
		}
	}
}
